<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "tenant".
 *
 * @property string $id ID
 * @property string $name 名称
 * @property string $identifier tenant标识符
 * @property string $appid appid
 * @property string $loyalty_url loyalty_url
 * @property string $loyalty_accountid loyalty_accountid
 * @property string $loyalty_username loyalty_username
 * @property string $loyalty_password loyalty_password
 * @property int $tenant_id tenant_id
 * @property string $webform_url webform_url
 * @property string $subdomain subdomain
 * @property int $updated_at 修改时间戳
 */
class Tenant extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tenant';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'appid'], 'required'],
            [['tenant_id', 'updated_at'], 'integer'],
            [['name', 'identifier', 'appid', 'loyalty_url', 'loyalty_accountid', 'loyalty_username', 'loyalty_password', 'subdomain'], 'string', 'max' => 255],
            [['webform_url'], 'string', 'max' => 1000],
            [['appid'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Tenant Name',
            'identifier' => 'tenant标识符',
            'appid' => 'Appid',
            'loyalty_url' => 'Loyalty Url',
            'loyalty_accountid' => 'Loyalty Accountid',
            'loyalty_username' => 'Loyalty Username',
            'loyalty_password' => 'Loyalty Password',
            'tenant_id' => 'Tenant ID',
            'webform_url' => 'Webform Url',
            'subdomain' => 'Subdomain',
            'updated_at' => 'Updated At',
        ];
    }

    public function save($runValidation = true, $attributeNames = null)
    {
        $this->updated_at = time();
        if ($this->getIsNewRecord()) {
            return $this->insert($runValidation, $attributeNames);
        }

        return $this->update($runValidation, $attributeNames) !== false;
    }
}
